<?php

   /*附件下载日志*/
			session_start();
            $u_id =  $_SESSION['think']['ADMIN_ID'];
			
           $names = $_SESSION['think']['name'];
            $str = "姓名:".$names."---ID:".$u_id."---操作内容：附件下载---数据ID:".$_GET['id']."---操作时间：".date('Y-m-d h:i:s',time());
            file_put_contents("down.log", $str.".\r\n", FILE_APPEND);  
   /*附件下载日志结束*/

//获取要下载的文件名
$link = mysqli_connect('127.0.0.1','root','root');
mysqli_select_db($link,'wanzhivip_com');
mysqli_set_charset($link,'utf-8');


	$sqls = " select * from cmf_role_user where user_id=".$u_id;
    $res = mysqli_query($link,$sqls);
    $res= mysqli_fetch_array($res);
  
	if($res['role_id']==5){
     	 $sql="UPDATE cmf_money_extend set down_time='".time()."' WHERE id=".$_GET['id'];
		mysqli_query($link,$sql);
    }



$filepath = __DIR__.'/upload/'.$filepath = $_GET['path'];

if(empty($_GET['path'])){
    echo "<script>alert('附件为空');history.back();</script>";
    exit;
}

$sys = getOS();
if($sys == 'mac' || $sys == 'iphone' || $sys == 'ipad'){
    //设置头信息
    $_GET['name'] = intval($_GET['name']);
    header('Content-Type: application/octet-stream; charset=utf-8');
    header('Content-Disposition: attachment; filename="' .$_GET['name']. '.docx"');
}else{
    //设置头信息
    header('Content-Disposition: attachment; filename="' . urlencode($_GET['name']). '"');
}


header('Content-Length:' . filesize($filepath));

//读取文件并写入到输出缓冲

readfile($filepath);

function getOS()
{
    $agent = strtolower($_SERVER['HTTP_USER_AGENT']);

    if (strpos($agent, 'windows nt')) {
        $platform = 'windows';
    } elseif (strpos($agent, 'macintosh')) {
        $platform = 'mac';
    } elseif (strpos($agent, 'ipod')) {
        $platform = 'ipod';
    } elseif (strpos($agent, 'ipad')) {
        $platform = 'ipad';
    } elseif (strpos($agent, 'iphone')) {
        $platform = 'iphone';
    } elseif (strpos($agent, 'android')) {
        $platform = 'android';
    } elseif (strpos($agent, 'unix')) {
        $platform = 'unix';
    } elseif (strpos($agent, 'linux')) {
        $platform = 'linux';
    } else {
        $platform = 'other';
    }
    return $platform;
}